﻿package java_45;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试HashMap的多个方法。
 */
public class TestMap {
    public static void main(String[] args) {
     
        Map countries = new HashMap();
        countries.put("CN", "中华人民共和国");
        countries.put("RU", "俄罗斯联邦");
        countries.put("FR", "法兰西共和国");
        countries.put("US", "美利坚合众国");
       
        String country = (String) countries.get("CN");
        System.out.println("CN对应的国家是:" + country);
        
        System.out.println("Map中共有"+countries.size()+"组数据");
        
        System.out.println("Map中包含FR的key吗?" + 
        countries.containsKey("FR"));
        countries.remove("FR");
        System.out.println("Map中包含FR的key吗?" + 
        countries.containsKey("FR"));
       
        System.out.println(countries.keySet());
        System.out.println(countries.values());
        System.out.println(countries);
      
        countries.clear();
        if(countries.isEmpty())
            System.out.println("已清空Map中数据！");
    }
}